import java.io.IOException;
import java.io.PrintWriter;

import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import BIll.BLLRoom;
import BIll.BLLRoom_user;
import BIll.BLLUser;
import tool.BllFactory;


public class AddUserServlet extends HttpServlet{
	private BllFactory bllFactory = BllFactory.getBllFactory();
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset = utf-8");
		
		String name = new String(request.getParameter("name").getBytes("ISO-8859-1"),"utf-8");
		String idcard = new String(request.getParameter("idcard").getBytes("ISO-8859-1"),"utf-8");
		int phone = Integer.parseInt(request.getParameter("phone"));
		int roomid = Integer.parseInt(request.getParameter("roomid"));
		String starttime = new String(request.getParameter("starttime").getBytes("ISO-8859-1"),"utf-8");
		int day = Integer.parseInt(request.getParameter("day"));
		
		
		BLLUser bllUser = bllFactory.getInstance(BLLUser.class);
		BLLRoom_user bllRoomUser = bllFactory.getInstance(BLLRoom_user.class);
		BLLRoom bllRoom = bllFactory.getInstance(BLLRoom.class);
		boolean b = bllUser.addUser(name, idcard, phone);
		boolean b1 = bllRoomUser.addRoomUser(idcard, roomid, starttime,day);
		boolean b2 = bllRoom.addUser(roomid);
		
		boolean check = false;
		if (b == true && b1 == true && b2 == true) {
			check = true;
		}
		
		
		PrintWriter pw = response.getWriter();
		pw.print(check);
		pw.close();
	}

}